/* xsh_rmdtest.c - xsh_rmdtest */

#include <xinu.h>
#include <stdio.h>
#include <string.h>

/*------------------------------------------------------------------------
 * xsh_rmdtest - test shell for ram disk device
 *------------------------------------------------------------------------
 */
shellcmd xsh_rmdtest(int nargs, char *args[])
{
	char testbuf[RMD_BLKSIZ];
	int i, j;
	int retval;
	struct ramblk *ramptr;
	ramptr = &ramtab[0];
	for( i=0;i<RMD_BLKSIZ;i++ ) {
		testbuf[i]=(char)(i%256);
	}
	retval = open(RAMDISK, "100", NULL);
	if( retval == OK ) {
		kprintf("Open OK!\r\n");
	}
	for ( i=0;i<ramptr -> maxsize;i++) {
		retval = write(RAMDISK, testbuf,i);
		for( j=0;j<RMD_BLKSIZ;j++ ) {
			if (testbuf[j] != (char)(j%256))
				kprintf("Write Wrong!\r\n");
			}
	}
	if( retval == OK ) {
		kprintf("Write OK!\r\n");
	}
	for ( i=0;i<ramptr -> maxsize;i++) {
		retval = read(RAMDISK, testbuf,i);
		for( j=0;j<RMD_BLKSIZ;j++ ) {
			if (testbuf[j] != (char)(j%256))
				kprintf("Read Wrong!\r\n");
			}
	}
	if( retval == OK ) {
		kprintf("Read OK!\r\n");
	}
	retval = close(RAMDISK);
	if( retval == OK ) {
		kprintf("Close OK!\r\n");
	}
	return OK;
}
